﻿Imports System
Imports System.CodeDom.Compiler
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports System.Reflection

Namespace System.Workflow.ComponentModel.Compiler
    <Serializable> _
    Public NotInheritable Class WorkflowCompilerParameters
        Inherits CompilerParameters
        ' Methods
        Public Sub New()
            Me.languageToUse = "CSharp"
        End Sub

        Public Sub New(ByVal assemblyNames As String())
            MyBase.New(assemblyNames)
            Me.languageToUse = "CSharp"
        End Sub

        Public Sub New(ByVal assemblyNames As String(), ByVal outputName As String)
            MyBase.New(assemblyNames, outputName)
            Me.languageToUse = "CSharp"
        End Sub

        Public Sub New(ByVal assemblyNames As String(), ByVal outputName As String, ByVal includeDebugInformation As Boolean)
            MyBase.New(assemblyNames, outputName, includeDebugInformation)
            Me.languageToUse = "CSharp"
        End Sub


        ' Properties
        Friend ReadOnly Property CheckTypes As Boolean
            Get
                Return Me.checkTypes
            End Get
        End Property

        Public Property CompilerOptions As String
            Get
                Return Me.compilerOptions
            End Get
            Set(ByVal value As String)
                Me.compilerOptions = value
                MyBase.CompilerOptions = Me.compilerOptions
                If ((Not value Is Nothing) AndAlso value.Contains("/nocode")) Then
                    Me.compileWithNoCode = True
                    MyBase.CompilerOptions = MyBase.CompilerOptions.Replace(" /nocode", "")
                    MyBase.CompilerOptions = MyBase.CompilerOptions.Replace("/nocode", "")
                Else
                    Me.compileWithNoCode = False
                End If
                If ((Not value Is Nothing) AndAlso value.Contains("/checktypes")) Then
                    Me.checkTypes = True
                    MyBase.CompilerOptions = MyBase.CompilerOptions.Replace(" /checktypes", "")
                    MyBase.CompilerOptions = MyBase.CompilerOptions.Replace("/checktypes", "")
                Else
                    Me.checkTypes = False
                End If
            End Set
        End Property

        Friend ReadOnly Property CompileWithNoCode As Boolean
            Get
                Return Me.compileWithNoCode
            End Get
        End Property

        Public Property GenerateCodeCompileUnitOnly As Boolean
            Get
                Return Me.generateCCU
            End Get
            Set(ByVal value As Boolean)
                Me.generateCCU = value
            End Set
        End Property

        Public Property LanguageToUse As String
            Get
                Return Me.languageToUse
            End Get
            Set(ByVal value As String)
                If String.IsNullOrEmpty(value) Then
                    Throw New ArgumentNullException("value")
                End If
                If ((String.Compare(value, SupportedLanguages.CSharp.ToString, StringComparison.OrdinalIgnoreCase) <> 0) AndAlso (String.Compare(value, SupportedLanguages.VB.ToString, StringComparison.OrdinalIgnoreCase) <> 0)) Then
                    Throw New NotSupportedException(SR.GetString("Error_LanguageNeedsToBeVBCSharp", New Object() { value }))
                End If
                Me.languageToUse = value
            End Set
        End Property

        Public ReadOnly Property LibraryPaths As StringCollection
            Get
                If (Me.libraryPaths Is Nothing) Then
                    Me.libraryPaths = New StringCollection
                End If
                Return Me.libraryPaths
            End Get
        End Property

        Friend Property LocalAssembly As Assembly
            Get
                Return Me.localAssembly
            End Get
            Set(ByVal value As Assembly)
                Me.localAssembly = value
            End Set
        End Property

        Friend Property ServiceProvider As IServiceProvider
            Get
                Return Me.serviceProvider
            End Get
            Set(ByVal value As IServiceProvider)
                Me.serviceProvider = value
            End Set
        End Property

        Public ReadOnly Property UserCodeCompileUnits As IList([Of] CodeCompileUnit)
            Get
                If (Me.userCodeCCUs Is Nothing) Then
                    Me.userCodeCCUs = New List([Of] CodeCompileUnit)
                End If
                Return Me.userCodeCCUs
            End Get
        End Property


        ' Fields
        Private checkTypes As Boolean
        Private compilerOptions As String
        Private compileWithNoCode As Boolean
        Private generateCCU As Boolean
        Private languageToUse As String
        Private libraryPaths As StringCollection
        Private localAssembly As Assembly
        Private serviceProvider As IServiceProvider
        Private userCodeCCUs As IList([Of] CodeCompileUnit)
    End Class
End Namespace

